package com.linzm.leetcode.primary.ilearning.demo0113;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zimingl
 * @Date 2023/1/14 1:19
 * @Description: 至少需要几个维修工人
 */
public class Demo2 {

    public static void main(String[] args) {
        int[][] num1 = {
                {2, 5, 6},
                {4, 3, 6},
                {2, 5, 4},
                {4, 3, 4},
                {2, 3, 4},
                {2, 5, 4}
        };
        int[] num2 = {3, 4, 5};
        Demo2 demo2 = new Demo2();
        int num = demo2.getCount(num1, num2);
        System.out.println(num);
    }

    private int getCount(int[][] num1, int[] num2) {
        List<Integer> list = new ArrayList<>();
        int num = 0, count;
        for (int i = 0; i < num1.length; i++) {
            count = 0;
            for (int j = 0; j < num1[i].length; j++) {
                if (num1[i][j] > num2[j]) {
                    count++;
                }
            }
            num = getNum(list, num);
            if (count > 1) {
                list.add(5);
                num++;
            }
            if (count == 1) {
                list.add(2);
                num++;
            }
        }
        return num;
    }

    private int getNum(List<Integer> list, int num) {
        for (int x = 0; x < list.size(); x++) {
            if (list.get(x) > 0) {
                list.set(x, list.get(x) - 1);
            } else {
                num--;
            }
        }
        return num;
    }
}
